import { Component, OnInit } from '@angular/core';
import { HttpClient } from '@angular/common/http';

@Component({
  selector: 'app-carouselpublic',
  templateUrl: './carouselpublic.component.html',
  styleUrls: ['./carouselpublic.component.css']
})
export class CarouselpublicComponent implements OnInit {
  // 获取轮播图并存入数组
  public getCarousel: any[] = [];
  // 声明http
  constructor(public http: HttpClient) { }
  ngOnInit() {
    // 轮播图
    setTimeout(() => {
      const mySwiper = new Swiper ('.swiper-container', {
        direction: 'horizontal',
        loop: true,
        // 分页器
        pagination: {
          el: '.swiper-pagination',
        },
        autoplay: {
          disableOnInteraction: false,
        },
      });
    }, 1000);
    // 获取轮播图图片的请求
    const getCarousel = 'http://192.168.2.228:8080/rotation/list';
    this.http.get(getCarousel).subscribe((response: any) => {
      console.log(response);
      this.getCarousel = response.data.list;
    });
  }
}
